package com.mutual.reins.trial.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.interf.entity.ReinsPolicyUnit;
import com.mutual.reins.trial.entity.TrialTreaty;
import com.mutual.reins.trial.mapper.TrialTreatyMapper;
import com.mutual.reins.trial.service.ITrialTreatyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CodeGenerate
 * @since 2021-04-28
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TrialTreatyServiceImpl extends ServiceImpl<TrialTreatyMapper, TrialTreaty> implements ITrialTreatyService {

    /**
     * 获取该对象Map（key：cerTiNo-dangerNo value：TrialTreaty）
     *
     * @param queryWrapper 查询条件
     * @return 获取该对象Map
     */
    @Override
    public Map<String, List<TrialTreaty>> selectTrialTreatyMap(QueryWrapper queryWrapper) {
        List<TrialTreaty> trialTreatyList = this.list(queryWrapper);
        Map<String,List<TrialTreaty>> trialTreatyMap = new HashMap<>(16);
        if(ObjectUtil.isNotNull(trialTreatyList) && !trialTreatyList.isEmpty()){
            for(TrialTreaty trialTreaty:trialTreatyList){
                if(trialTreatyMap.containsKey(trialTreaty.getCerTiNo()+"-"+trialTreaty.getDangerNo())){
                    List<TrialTreaty> trialTreatyListMap = trialTreatyMap.get(trialTreaty.getCerTiNo()+"-"+trialTreaty.getDangerNo());
                    trialTreatyListMap.add(trialTreaty);
                }else{
                    List<TrialTreaty> trialTreatyListMap = new ArrayList<>();
                    trialTreatyListMap.add(trialTreaty);
                    trialTreatyMap.put(trialTreaty.getCerTiNo()+"-"+trialTreaty.getDangerNo(),trialTreatyListMap);
                }

            }
        }
        return trialTreatyMap;
    }
}
